<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "member".
 *
 * @property integer $id
 * @property string $username
 * @property string $qq
 * @property string $mobile
 * @property integer $usertype
 * @property integer $status
 * @property string $zhuangtai
 * @property string $product
 * @property string $channel
 * @property string $note
 * @property integer $create_time
 * @property string $alias

 */
class Member extends \yii\db\ActiveRecord
{
    const STATUS_NORMAL = 1;//正常
    const STATUS_DENYLOGIN = 0;//禁止登录

    public $order_number;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'member';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['usertype', 'status', 'create_time'], 'integer'],
            [['zhuangtai', 'note'], 'string'],
            [['username','alias'], 'string', 'max' => 128],
            [['channel'], 'string', 'max' => 64],
            [['product'], 'string', 'max' => 32],
            [['password'], 'string', 'max' => 32],
            [['qq', 'mobile'], 'string', 'max' => 16],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'username' => '用户名',
            'qq' => 'qq号码',
            'mobile' => '电话号码',
            'usertype' => '用户类型',
            'status' => '账户状态',
            'zhuangtai' => '状态',
            'note' => '备注',
            'create_time' => '创建时间',
            'password' => '密码',
            'channel' => '渠道',
            'product' => '产品名称',
            'alias' => '别名',
        ];
    }

    public function save($runValidation = true, $attributeNames = null)
    {
        if($this->isNewRecord) {
            $this->create_time=time();
        }
        return parent::save($runValidation, $attributeNames);
    }

    public function generatePassword($password)
    {
        $this->password = $this->encry($password);
        return;
    }
    public function encry($password)
    {
        return md5($password);
    }
}
